<?php

/** 
 * 已完成订单同步队列
 * 
 */
class Order_sync_queue_mdl extends Mongo_Model {
	
	/**
	 */
	function __construct() {
		$this->collName = 'orderSyncQueue';
		parent::__construct();
	}
	
	function enqueue($orderID=0,$userID=0,$mid=0){
		$doc = array(
				'oid'=>(int)$orderID,//分表订单ID
				'uid'=>(int)$userID,//用户ID
				'mid'=>(int)$mid,// 主表订单ID
				'ok'=>0,
		);
		return $this->insert($doc);
	}
	
	function dequeue(){
		$where = array('ok'=>0);
		$update = array('$set'=>array('ok'=>1));
		$fields = array('_id'=>FALSE,'ok'=>FALSE);
		$options = array('$juseOne'=>1);
		return $this->coll->findAndModify($where,$update,$fields,$options);
// 		return $this->findOne($where);
	}
	
	function clear(){
		$where = array('ok'=>1);
		return $this->coll->remove($where);
	}
	
	
	
}

